//
// Created by 15760 on 2022/11/7.
//
#include "player.h"

Player::Player(unsigned int n) : no(n), coin(3) {
    cards.push_back(const_cast<Card *>(&CardsTab::getInstance().getCard(n)));  //获得一张麦田
    cards.push_back(const_cast<Card *>(&CardsTab::getInstance().getCard(4 + n)));  //获得一张面包店
}

void Player::addACard(const Card& card) {
    cards.push_back(const_cast<Card *>(&card));
}

void Player::exchangeACard(const vector<Card*>::iterator pos, const Card& card) {
    cards.erase(pos);
//    cards.insert(pos, const_cast<Card*>(&card));
    cards.push_back(const_cast<Card*>(&card));
}

const bool Player::haveTrainStation() const {
    bool have = false;
    for (auto card : cards) {
        if (card->getType() == 5) {
            have = true;
            break;
        }
    }
    return have;
}

const bool Player::haveSameTypeCard(const Card &card) const {
    bool have = false;
    for (auto c : cards) {
        if (c->getType() == card.getType()) {
            have = true;
            break;
        }
    }
    return have;
}

